package io.xccit.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.xccit.pojo.param.ProductByCategoryParam;
import io.xccit.pojo.param.ProductHotsParam;
import io.xccit.pojo.param.ProductIDParam;
import io.xccit.pojo.param.ProductPromoParam;
import io.xccit.result.AjaxResult;
import io.xccit.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author CH_ywx
 * @date 2023-09-10
 * @description
 */
@ApiModel("商品接口")
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @ApiOperation("热门商品类别")
    @PostMapping("/promo")
    public AjaxResult promo(
                            @RequestBody
                            @ApiParam(value = "商品类别热门参数",required = true)
                            ProductPromoParam productPromoParam){

        return productService.promo(productPromoParam.getCategoryName());
    }

    @PostMapping("/hots")
    @ApiOperation("热门商品获取")
    public AjaxResult hotsProduct(@RequestBody ProductHotsParam productHotsParam){
        return productService.hotsProduct(productHotsParam);
    }

    @ApiOperation("所有商品类型接口")
    @PostMapping("/category/list")
    public AjaxResult categoryList(){
        return productService.categoryList();
    }

    @ApiOperation("根据类别获取商品")
    @PostMapping("/bycategory")
    public AjaxResult selectProductByCategory(@RequestBody ProductByCategoryParam productByCategoryParam){
        return productService.selectProductByCategory(productByCategoryParam);
    }

    @ApiOperation("获取全部商品")
    @PostMapping("/all")
    public AjaxResult selectAllProduct(@RequestBody ProductByCategoryParam productByCategoryParam){
        return productService.selectProductByCategory(productByCategoryParam);
    }

    @ApiOperation("获取商品详情")
    @PostMapping("/detail")
    public AjaxResult detail(@RequestBody ProductIDParam productIDParam){
        return productService.detail(productIDParam.getProductID());
    }

    @ApiOperation("获取商品图片")
    @PostMapping("/pictures")
    public AjaxResult pictures(@RequestBody ProductIDParam productIDParam){
        return productService.pictures(productIDParam.getProductID());
    }
}
